import config from '@/config'
import RequestBase from '@/utils/request.js'
import { AESencrypt } from '@/utils/auth.js'

const baseRequest = new RequestBase(config.baseUrl)

// 登录方法
export function login(username, password, platform) {
  const data = {
    username,
    password,
    platform
  }

  // 加密
  const params = {
    account: username,
    password: AESencrypt(password, username)
  }
  const headers = {
    isToken: false
  }
  return baseRequest.post('/portal/auth/login', params, headers)
}

// 获取用户详细信息
export function getInfo() {
  return baseRequest.get('/portal/auth/common/api/v1/account/info')
}

// 退出方法
export function logout() {
  return baseRequest.post('/portal/auth/common/api/v1/logout')
}

// 修改密码
export const updateUserPwd = (data) => {
  console.log('dsdsdsdssdsdsds')
  return baseRequest.post(`/portal/auth/account/modify-password`, data)
}

// 停机页面刷新时发送
export function tyrConnect() {
  return baseRequest.get('/system/apkUpgrade/apkUrl')
}

//获取短信验证码
export function getSmsCode(phoneNumber) {
  return baseRequest.post(`/sendSmsCode/${phoneNumber}`)
}

//短信验证码登录
export function loginBySmsCode(data) {
  return baseRequest.post('/smsLogin', data)
}
